/*
 * Copyright (c) 2012 RTCLab
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification, are
 * permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this list of
 *    conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
 *    of conditions and the following disclaimer in the documentation and/or other materials
 *    provided with the distribution.
 *
 */

package com.rtckit {
	
public class RingManager {
	private var rings:Object = {};
	private var dtmf:Object = {};

	public function RingManager() {
		dtmf['1'] = new DTMFPlayer(697, 1209);
		dtmf['2'] = new DTMFPlayer(697, 1336);
		dtmf['3'] = new DTMFPlayer(697, 1477);
		dtmf['4'] = new DTMFPlayer(770, 1209);
		dtmf['5'] = new DTMFPlayer(770, 1336);
		dtmf['6'] = new DTMFPlayer(770, 1477);
		dtmf['7'] = new DTMFPlayer(852, 1209);
		dtmf['8'] = new DTMFPlayer(852, 1336);
		dtmf['9'] = new DTMFPlayer(852, 1477);
		dtmf['*'] = new DTMFPlayer(941, 1209);
		dtmf['0'] = new DTMFPlayer(941, 1336);
		dtmf['#'] = new DTMFPlayer(941, 1477);
	}

	public function addSound(name:String, file:String, loops:Number = 1000):void {
		if (file)
			rings[name] = new RingSound(file, loops);
	}
	
	public function play(name:String):void {
		var ring:RingSound = rings[name];
		if (ring)
			ring.play();
	}
	
	public function dial(digits:String):void {
		if (!digits)
			return;
		var sound:DTMFPlayer = dtmf[digits.charAt(0)];
		if (sound)
			sound.play();
	}
	
	public function stopAll():void {
		for (var name:String in rings) {
			rings[name].stop();
		}
	}
	
}
	
}